{% extends "layout.html" %}

{% block css_m %}
    <style>
        th {
            text-align: center
        }

        strong {
            font-size: 16px;

        }
    </style>

{% endblock %}
{% block js_m %}
{% endblock %}
{% block content_body %}

    <div class="jumbotron" style="width: auto; padding-top: 0; margin-top: 0">


        <div class="container" style="margin-top: 0">
            <div class="row">
                <div class="col-md-10">
                    <h2 style="text-align: center">{{ result.name }}
                        <small> {{ result.get_sex_display }} {{ result.age }}岁</small>
                        <div class="btn-group" role="group">
                            <a style="margin-left: 10px" class="btn btn-primary"
                               href="/camera/{{ result.pid }}/add_test.html"><span
                                    class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> 鼻道镜检查</a>
                            <a class="btn btn-warning" href="/buying/{{ result.pid }}/add.html/"><span
                                    class="glyphicon glyphicon-usd" aria-hidden="true"></span> 新订单</a>
                            <a href="/returning_visits/{{ result.pid }}/list.html/" class="btn btn-default"><span
                                    class="glyphicon glyphicon-earphone" aria-hidden="true"></span> 回访</a>
                        </div>
                    </h2>
                </div>

                <div class="col-md-6">
                    <table class="table table-striped table-hover" style="width: 500px">
                        <tr>
                            <td>联系方式</td>
                            <td>{{ result.phone }}</td>
                        </tr>
                        <tr>
                            <td>主要症状</td>
                            <td>{{ result.symptom }}</td>
                        </tr>
                        <tr>
                            <td>病史</td>
                            <td>{{ result.ill_date_period }}</td>
                        </tr>
                        <tr>
                            <td>首次进店</td>
                            <td>{{ result.create_time }}</td>
                        </tr>
                        <tr>
                            <td>上次进店</td>
                            <td id="last_in"></td>
                        </tr>


                    </table>
                </div>


                <div class="col-md-6">
                    <table class="table table-striped table-hover" style="width: 500px">
                        <tr>
                            <td>试用次数</td>
                            <td id="trail_counts_td">{{ result.trial_counts }}次</td>
                        </tr>
                        <tr>
                            <td>治疗次数</td>
                            <td id="test_total"></td>
                        </tr>
                        <tr>
                            <td>购买次数</td>
                            <td id="buying_total"></td>
                        </tr>
                        <tr>
                            <td>意向状态</td>
                            <td id="stft">{{ result.create_time }}</td>
                        </tr>

                        <tr>
                            <td>消费金额</td>
                            <td id="total_cost"></td>
                        </tr>
                    </table>
                </div>


            </div>
        </div>
    </div>





    <div class="page-jumbotron center-block " style="width: auto">
        <ul class="nav nav-tabs nav-justified center-block">
            <li id="test_list" role="presentation" class="active"><a href="#"><span class="glyphicon glyphicon-tasks"
                                                                                    aria-hidden="true"></span> <strong>检查及治疗</strong></a>
            </li>

            <li id="buying_list" role="presentation"><a href="#"><span class="glyphicon glyphicon-usd"
                                                                       aria-hidden="true"></span> <strong>购买记录</strong></a>
            </li>
        </ul>

    </div>
    <div id="test_list_div" style="width: 1200px; margin: 0 auto; padding-top: 20px; min-height: 1000px;">

        <table class="table table-striped table-hover" style="text-align: center">
            <thead>
            <tr style="text-align: center">

                <th>就诊日期</th>
                <th>本次症状</th>
                <th>客户状态</th>

                <th>服务项目</th>
                <th>满意度</th>


                <th> 操作 <a class="btn btn-primary btn-xs" href="/test/{{ result.pid }}/add.html/"><span
                        class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> 新建</a></th>


            </tr>
            </thead>
            <tbody>
            {% for each in result_test_list %}
                <tr>

                    <td>{{ each.test_date }}</td>
                    <td>{{ each.symptom }}</td>
                    <td>{{ each.get_trail_or_bought_display }}</td>
                    <td>{{ each.test_treatment }}</td>
                    <td>{{ each.get_satisfaction_display }}</td>


                    <td>
                        <div class="btn-group btn-group-sm" role="group">

                            <a class="btn btn-primary" href="/camera/{{ each.test_id }}/test.html/"><span
                                    class="glyphicon glyphicon-facetime-video" aria-hidden="true" title="鼻道镜检查"></span> </a>
                            <a class="btn btn-default" href="/test_report/{{ each.test_id }}/edit.html/"><span
                                    class="glyphicon glyphicon-folder-open" aria-hidden="true" title="查看/修改检查报告"></span> </a>
                            <a class="btn btn-info" href="/test/{{ each.test_id }}/edit.html/">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true" title="修改就诊信息"></span> </a>
                            <a class="btn btn-danger del_test" href="#" id="{{ each.test_id }}"><span
                                    class="glyphicon glyphicon-trash" aria-hidden="true" title="删除就诊信息"></span> </a>
                        </div>
                    </td>

                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>

    <div id="buying_list_div" class="hidden "
         style="width: 1200px; margin: 0 auto; padding-top: 20px; min-height: 1000px;">
        <table class="table table-striped table-hover" style="text-align: center">
            <thead>
            <tr style="text-align: center">

                <th>购买日期</th>
                <th>至今</th>
                <th>用户id</th>
                <th>订单号</th>
                <th>原价</th>

                <th>实付</th>
                <th>订单状态</th>
                <th>经办人</th>

                <th>操作 <a class="btn btn-warning btn-xs" href="/buying/{{ result.pid }}/add.html/"><span
                        class="glyphicon glyphicon-usd" aria-hidden="true"></span> 新订单</a></th>


            </tr>
            </thead>
            <tbody>
            {% for each in result_buying_list %}
                <tr>

                    <td>{{ each.buying_date }}</td>
                    <td>{{ each.last_bought }}天</td>
                    <td>{{ each.pid }}</td>
                    <td>{{ each.order_id }}</td>

                    <td>{{ each.bill_amount_bf_dst }}</td>
                    <td>{{ each.total_amount }}</td>
                    <td>{{ each.get_bill_status_display }}</td>
                    {% if each.operator.nick_name %}
                        <td id="bill_operator">{{ each.operator.nick_name }}</td>
                    {% else %}
                        <td id="bill_operator">{{ each.operator.user_name }}</td>
                    {% endif %}
                    <td>
                        <div class="btn-group btn-group-sm" role="group">
                        <a class="btn btn-default" href="/buying/{{ each.buying_id }}/check.html/"><span class="glyphicon glyphicon-folder-open" aria-hidden="true" title="查看订单"></span> </a>
                        <a class="btn btn-info" href="/buying/{{ each.buying_id }}/edit.html/"><span class="glyphicon glyphicon-pencil" aria-hidden="true" title="修改订单"></span> </a>
                        </div>
                    </td>

                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <input id="trail_counts_pid" class="hidden" value="{{ result.pid }}"/>

{% endblock %}

{% block content_bottom %}
    {#模态对话框#}

    <div class="modal fade " id="add-modal_id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true" style="z-index: 10000">
        <div class="modal-dialog modal-lg" style="width: 1000px">
            <div class="alert alert-danger" role="alert">
            <div class="modal-content">
                <div class="modal-header">

                    <h1 class="modal-title" id="myModalLabel">
                        删除确认：
                    </h1>
                </div>

                <div class="modal-body">
                    <h2 style="text-align: center"><strong><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> 警告，是否确认删除此条记录！</strong></h2>


                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" id="m_conf" style="margin-left: 60px">确定
                    </button>
                    <button type="button" class="btn btn-default" id="m_close">取消
                    </button>

                </div>

            </div><!-- /.modal-content -->
                </div>
        </div><!-- /.modal -->
    </div>
    <script>
        var TESTid
        $('#test_list').click(function () {

            $(this).tab('show');
            $("#test_list_div").removeClass('hidden');

            $("#buying_list_div").addClass('hidden');

        });


        $('#buying_list').click(function () {

            $(this).tab('show');
            $("#buying_list_div").removeClass('hidden');
            $("#test_list_div").addClass('hidden');


        })
        $(function () {
            $(".del_test").on("click", function () {
                $('#add-modal_id').modal('show');
                TESTid = $(this).attr("id")

            });
            $("#m_close").click(function () {

                $('#add-modal_id').modal('hide');
            });
            $("#m_conf").click(function () {

                $('#add-modal_id').modal('hide');
                $.ajaxSetup({

                    data: {csrfmiddlewaretoken: '{{ csrf_token }}'},

                });
                $.ajax({
                        url: '{% url "test_del" %}',
                        type: 'POST',
                        data: {"test_id": TESTid,},

                        dataType: 'JSON',
                        success: function (arg) {
                            if (arg["ret"]) {
                                location.reload()
                            }


                        }

                    }
                );
            });

            $("#last_in").text($('#test_list_div table tbody').find('td:first').text());
            var stft_td = $($('#test_list_div table tbody tr').find('td:last')[0]).prev().prev()
            $("#stft").text($(stft_td).text());

            var test_total_c = -1;
            $('#test_list_div table ').find('tr').each(function () {
                test_total_c++;
            });
            $("#test_total").text(test_total_c + '次');
            var buying_total_c = -1;
            $('#buying_list_div table ').find('tr').each(function () {
                buying_total_c++;
            });
            $("#buying_total").text(buying_total_c + '次');

        })
        $(document).ready(function () {
            $.ajaxSetup({

                data: {csrfmiddlewaretoken: '{{ csrf_token }}'},

            });
            $.ajax({
                url: '/refresh_trail_counts.html/',
                type: 'POST',
                data: {
                    'pid': $("#trail_counts_pid").val(),

                },
                dataType: 'JSON',

                success: function (arg) {
                    var trail_counts = arg["trail_counts"]
                    var total_pay = arg["total_pay"]
                    $("#trail_counts_td").text(trail_counts + "次")
                    $("#total_cost").text(total_pay + "元")
                }

            })

        })
    </script>

{% endblock %}